/*
 *打开无模式窗口
 *theUrl 打开目标页面 
 *winName 页面标题
 *features 页面特征如：大小等
 */
function openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

/*取得今日日期*/
function GetTodayDate()
{
	today= new Date();
	y= today.getYear();
	m= (today.getMonth() + 1);
	if (m<10)
	{
		m='0'+m;
	}
	d= today.getDate();
	if (d<10)
	{
		d='0'+d;
	}
	return y+'-'+m+'-'+d;
}

/*
 *比较两个日期大小
 *str1 日期字符串1
 *str2 日期字符串2
 *如果str1大于str2则返回False,否则返回True
 */
function checkSeach(str1,str2){
	var result=str1.localeCompare(str2);
	if(result>0){
		return false;
	}
	return true; 
}



/*
 * 验证表单提交参数是否合法
 * name 参数名标识用于提示框提示名
 * date 参数值
 * allowednull 是否可为空 true 或 false 
 */
function checkstring(name,data,allowednull)
{
	var datastr = data;
	var lefttrim = datastr.search(/\S/gi);

	if (lefttrim == -1) {
		if (allowednull) {
			return 1;
		} else {
			alert("请输入" + name + "！");
			return -2;
		}
	}

	if (datastr.search(/[<>]/gi) != -1) {
		alert("" + name + "中包含非法字符<>");
		return -1;
	}
	return 0;
}

/*
 * 验证填写邮件是否合法
 * name 参数名标识用于提示框提示名
 * date 参数值
 * allowednull 是否可为空 true 或 false 
 */
function checkemail(name, data, allowednull)
{
	var datastr = data;
	var lefttrim = datastr.search(/\S/gi);

	if (lefttrim == -1) {
		if (allowednull) {
			return 1;
		} else {
			alert("请输入一个正确的E-mail地址！");
			return -1;
		}
	}
	var myRegExp = /[a-z0-9](([a-z0-9]|[_\-\.][a-z0-9])*)@([a-z0-9]([a-z0-9]|[_\-][a-z0-9])*)((\.[a-z0-9]([a-z0-9]|[_\-][a-z0-9])*)*)/gi;
	var answerind = datastr.search(myRegExp);
	var answerarr = datastr.match(myRegExp);

	if (answerind == 0 && answerarr[0].length == datastr.length)
	{
		return 0;
	}

	alert("请输入一个正确的E-mail地址！");
	return -1;
}

/*
 *将日期中月份与日中2位数中第一位为0的过滤成1位数 如:01->1
 */ 
function parseNum(theNum){
	if (theNum.substring(0,1)==0)
		theNum=theNum.substring(1);
	return theNum;
}

/*
 *判断输入日期值是否合法
 */
function parseYMD(theYear,theMonth,theDay) {
	theYear=parseNum(theYear);
	theMonth=parseNum(theMonth);
	theDay=parseNum(theDay);
	if ((theYear < 1900) || (theYear > 3000)){
		return 1;
	}
	if (theMonth < 1 || theMonth > 12){
		return 2;
	}
	if ((theMonth==1 || theMonth==3 || theMonth==5 || theMonth==7 || theMonth==8 || theMonth==10 || theMonth==12) &&
			(theDay <1 || theDay > 31)
	){
		return 3;
	}
	if ((theMonth==4 || theMonth==6 || theMonth==9 || theMonth==11) &&
			(theDay <1 || theDay > 30)
	){
		return 3;
	}
	if (theYear%400==0 || (theYear%4==0 && theYear%100!=0)){  //闰年
		if (theMonth==2 && (theDay <1 || theDay > 29) )
			return 3;
	}
	else  //平年
		if (theMonth==2 && (theDay <1 || theDay > 28) )
			return 3;
	return 0;
}

/*
 *判断输入日期值长度格式是否合法
 *theDae 日期值
 *separator 日期分割符 如"-"
 */
function isInvalidDate(theDate,separator){
	default_style=1;
	if (theDate.length>10 || theDate.length<8)
		return true;
	idx1=theDate.indexOf(separator);
	if (idx1==-1)
		return true;
	idx2=theDate.indexOf(separator,idx1+1);
	if (idx2==-1)
		return true;
	if (isInvalidDate.arguments.length>2)
		default_style=isInvalidDate.arguments[2];
	if (default_style<1 || default_style>9){
		alert("传入参数有误！请检查。");
		return true;
	}
	if (default_style==1){
		theYear=theDate.substring(0,idx1);
		theMonth=theDate.substring(idx1+1,idx2);
		theDay=theDate.substring(idx2+1);
	}
	if (default_style==2){
		theMonth=theDate.substring(0,idx1);
		theDay=theDate.substring(idx1+1,idx2);
		theYear=theDate.substring(idx2+1);
	}
	if (theDay.length>2)
		return true;
	if (parseYMD(theYear,theMonth,theDay)>0)
		return true;
	else
		return false;
}

/*
 *把list框里的项 移到 别一个list框中 从 obj1->obj2
 */
function move_item(obj1,obj2)
{
	if (obj1.length>0){
		for(var Sselected=obj1.selectedIndex;Sselected>=0;Sselected=obj1.selectedIndex){
			var Sselected=obj1.selectedIndex;
			if (Sselected>=0){
				var SOption=obj1.options[Sselected];                         
				var oOption = new Option(SOption.text, SOption.value, true, true);                        
				obj1.remove(Sselected);
				if(repeat_item(SOption,obj2)){
					obj2.add(oOption);
				}
			}
		}
	}
}

/*
 *把list框里的所有的项 移到 另一个list框可 从 obj1->obj2 [可移值]
 */
function move_all_item(obj1,obj2)
{
	var menuitemcount=obj1.options.length;
	for(var i=0;i<=menuitemcount-1;i ++){
		var SOption=obj1.options[0];
		obj1.remove(0);
		if(repeat_item(SOption,obj2)){
			obj2.options.add(SOption);
		}
	}
	return;
}

/**
 * 检查是否有重复的值
 */
function repeat_item(sOption,obj2){
	for(var i=0;i<obj2.options.length;i++){
		if(sOption.value==obj2.options[i].value){
			return false;
		}
	}
	return true;
}

/*
 * 列表框全选
 */
function selectall(obj){
	for(var i=0;i<obj.length; i++){
		obj.options[i].selected=true;
	}
	return;
}